<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Video I/O with OpenCV Overview</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Video I/O with OpenCV Overview </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h3>See also:</h3>
<ul>
<li><a class="el" href="../../dd/de7/group__videoio.html">Video I/O Code Reference</a></li>
<li>Tutorials: <a class="el" href="../../de/d3d/tutorial_table_of_content_app.html">Application utils (highgui, imgcodecs, videoio modules)</a></li>
</ul>
<h1>General Information </h1>
<p>The OpenCV <a class="el" href="../../dd/de7/group__videoio.html">Video I/O</a> module is a set of classes and functions to read and write video or images sequence.</p>
<p>Basically, the module provides the <a class="el" href="../../d8/dfe/classcv_1_1VideoCapture.html" title="Class for video capturing from video files, image sequences or cameras. ">cv::VideoCapture</a> and <a class="el" href="../../dd/d9e/classcv_1_1VideoWriter.html" title="Video writer class. ">cv::VideoWriter</a> classes as 2-layer interface to many video I/O APIs used as backend.</p>
<div class="image">
<object type="image/svg+xml" data="../../videoio_overview.svg">videoio_overview.svg</object>
<div class="caption">
Video I/O with OpenCV</div></div>
<p> Some backends such as Direct Show (DSHOW), Microsoft Media Foundation (MSMF), Video 4 Linux (V4L), etc... are interfaces to the video I/O library provided by the operating system.</p>
<p>Some others backends like OpenNI2 for Kinect, Intel Perceptual Computing SDK, GStreamer, XIMEA Camera API, etc... are interfaces to proprietary drivers or to external library.</p>
<p>See the list of supported backends here: <a class="el" href="../../d4/d15/group__videoio__flags__base.html#ga023786be1ee68a9105bf2e48c700294d" title="cv::VideoCapture API backends identifier. ">cv::VideoCaptureAPIs</a></p>
<dl class="section warning"><dt>Warning</dt><dd>Some backends are experimental use them at your own risk </dd></dl>
<dl class="section note"><dt>Note</dt><dd>Each backend supports devices properties (<a class="el" href="../../d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d" title="cv::VideoCapture generic properties identifier. ">cv::VideoCaptureProperties</a>) in a different way or might not support any property at all.</dd></dl>
<h2>Select the backend at runtime </h2>
<p>OpenCV automatically selects and uses first available backend (<code>apiPreference=<a class="el" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294da77ab1fe260fd182f8ec7655fab27a31d" title="Auto detect == 0. ">cv::CAP_ANY</a></code>).</p>
<p>As advanced usage you can select the backend to use at runtime. Currently this option is available only with VideoCapture.</p>
<p>For example to grab from default camera using Direct Show as backend</p>
<div class="fragment"><div class="line"><span class="comment">//declare a capture object</span></div><div class="line"><a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html">cv::VideoCapture</a> cap(0, <a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294dab6ac3effa04f41ed5470375c85a23504">cv::CAP_DSHOW</a>);</div><div class="line"></div><div class="line"><span class="comment">//or specify the apiPreference with open</span></div><div class="line">cap.open(0, <a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294dab6ac3effa04f41ed5470375c85a23504">cv::CAP_DSHOW</a>);</div></div><!-- fragment --><p>If you want to grab from a file using the Direct Show as backend:</p>
<div class="fragment"><div class="line"><span class="comment">//declare a capture object</span></div><div class="line"><a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html">cv::VideoCapture</a> cap(filename, <a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294dab6ac3effa04f41ed5470375c85a23504">cv::CAP_DSHOW</a>);</div><div class="line"></div><div class="line"><span class="comment">//or specify the apiPreference with open</span></div><div class="line">cap.open(filename, <a class="code" href="../../d4/d15/group__videoio__flags__base.html#gga023786be1ee68a9105bf2e48c700294dab6ac3effa04f41ed5470375c85a23504">cv::CAP_DSHOW</a>);</div></div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed" title="Opens a video file or a capturing device or an IP video stream for video capturing. ">cv::VideoCapture::open()</a> , <a class="el" href="../../d8/dfe/classcv_1_1VideoCapture.html#a57c0e81e83e60f36c83027dc2a188e80" title="Default constructor. ">cv::VideoCapture::VideoCapture()</a></dd></dl>
<h4>How to enable backends</h4>
<p>There are two kinds of videoio backends: built-in backends and plugins which will be loaded at runtime (since OpenCV 4.1.0). Use functions <a class="el" href="../../de/db1/group__videoio__registry.html#ga6a5310ef846956a4c38dcd293bbab5d3" title="Returns list of all available backends. ">cv::videoio_registry::getBackends</a>, <a class="el" href="../../de/db1/group__videoio__registry.html#ga9068310d50ef430c2f5f6b185a99a24b" title="Returns true if backend is available. ">cv::videoio_registry::hasBackend</a> and <a class="el" href="../../de/db1/group__videoio__registry.html#ga6723e68832186e20bd44cd3c2b0d8c60" title="Returns backend API name or &quot;UnknownVideoAPI(xxx)&quot;. ">cv::videoio_registry::getBackendName</a> to check actual presence of backend during runtime.</p>
<p>To enable built-in videoio backends:</p><ol type="1">
<li>Enable corresponding CMake option, e.g. <code>-DWITH_GSTREAMER=ON</code></li>
<li>Rebuild OpenCV</li>
</ol>
<p>To enable dynamically-loaded videoio backend (currently supported: GStreamer and FFmpeg on Linux, MediaSDK on Linux and Windows):</p><ol type="1">
<li>Enable backend and add it to the list of plugins: <code>-DWITH_GSTREAMER=ON -DVIDEOIO_PLUGIN_LIST=gstreamer</code> CMake options</li>
<li>Rebuild OpenCV</li>
<li>Check that <code>libopencv_videoio_gstreamer.so</code> library exists in the <code>lib</code> directory</li>
</ol>
<dl class="section note"><dt>Note</dt><dd>Don't forget to clean CMake cache when switching between these two modes</dd></dl>
<h4>Use 3rd party drivers or cameras</h4>
<p>Many industrial cameras or some video I/O devices don't provide standard driver interfaces for the operating system. Thus you can't use VideoCapture or VideoWriter with these devices.</p>
<p>To get access to their devices, manufactures provide their own C++ API and library that you have to include and link with your OpenCV application.</p>
<p>It is a common case that these libraries read/write images from/to a memory buffer. If it so, it is possible to make a <code>Mat</code> header for memory buffer (user-allocated data) and process it in-place using OpenCV functions. See <a class="el" href="../../d3/d63/classcv_1_1Mat.html#a2c4229732da267f1fe385458af3896d8">cv::Mat::Mat()</a> for more details.</p>
<h2>The FFmpeg library </h2>
<p>OpenCV can use the FFmpeg library (<a href="http://ffmpeg.org/">http://ffmpeg.org/</a>) as backend to record, convert and stream audio and video. FFmpeg is a complete, cross-reference solution. If you enable FFmpeg while configuring OpenCV than CMake will download and install the binaries in <code>OPENCV_SOURCE_CODE/3rdparty/ffmpeg/</code>. To use FFmpeg at runtime, you must deploy the FFmpeg binaries with your application.</p>
<dl class="section note"><dt>Note</dt><dd>FFmpeg is licensed under the GNU Lesser General Public License (LGPL) version 2.1 or later. See <code>OPENCV_SOURCE_CODE/3rdparty/ffmpeg/readme.txt</code> and <a href="http://ffmpeg.org/legal.html">http://ffmpeg.org/legal.html</a> for details and licensing information </dd></dl>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:33 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
